package com.tongtech.space.common.pojo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 接口统一返回数据对象
 *
 * @author jinjiayu
 * @since 2021/1/14
 */
@Data
@Accessors(chain = true)
public class Result<T> {

    @ApiModelProperty("实际传输的数据")
    private T data;

    @ApiModelProperty("数据总记录数,以便前端分页")
    private Integer count = 1;

    @ApiModelProperty
    private boolean status = true;

    @ApiModelProperty
    private String message = "操作成功";

    public Result() {}


    public static Result<?> success() {
        return successMsg("操作成功");
    }

    public static Result<?> successMsg(String msg) {
        return (new Result<>()).setStatus(true).setMessage(msg);
    }

    public static Result<?> successSingle(Object data) {
        return success(data, 1);
    }

    public static Result<?> success(Object data, Long count) {
        return success(data, count.intValue());
    }

    public static Result<?> success(Object data, Integer count) {
        return (new Result<>()).setStatus(true).setData(data).setCount(count);
    }

    public static Result<?> fail() {
        return fail("操作失败");
    }

    public static Result<?> fail(Object data,String msg) {
        return (new Result<>()).setStatus(false).setData(data);

    }

    public static Result<?> fail(String msg) {
        return (new Result<>()).setStatus(false).setMessage(msg).setCount(0);
    }

    public boolean isStatus() {
        return this.status;
    }

}
